<?php 
require 'Model.php';
class IndexModel extends Model{
	function __construct(){
		parent::__construct();
		//$this->mod = 'carbrand';
	}
		function redirect($url, $msg)
{	  
   echo $msg.'<a href="'.$url.'">如果没有跳转，请点这里跳转</a>';
   header("refresh:3;url=$url"); 
}
function search($text){
	$sql="select * from carphoto where carname='".$text['key']."'";

	  $data = $this->conn->query($sql);
 	 return $data;
}















	function login()
	{
  $username = $_POST["username"];
$pwd = $_POST["password"];
  $sql = "select * from admins where adminname='".$username."' and password='".$pwd."'"; 
  var_dump($sql);
  $data = $this->conn->query($sql);
  return $data;
	}

	function getct(){
		$sql="select * from cartype";
		$data= $this->conn->query($sql);
		return $data;
	}
	function getCbl($data){

		$list=array();
		foreach ($data as $key ) {
			
			$sql="select * from carphoto left join cartype on carphoto.tid=cartype.tid left join carbrand on carphoto.bid=carbrand.bid  where carphoto.tid=".$key['tid'];
			//var_dump($sql);

			$li= $this->conn->query($sql);
			//$li['typename']=$key['cartypename'];
			$list[]=$li;
		}


		return $list;
	} 
		function getbt(){
		$sql="select * from carbrand";
		$data= $this->conn->query($sql);
		return $data;
	}






	function add($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  				}
			  else{
			  	$pic='';
			  }

			  $one = array(
					'uname' => trim($data['username']),  
					'password' => $data['password'],
					'gender' => $data['gender'],
					'birthdate' => $data['birthdate'],
					'hobby' => implode($data['hobby'], ','),
					'degree' => $data['degree'],
					'intro' => $data['intro'],
					'pic'=>$pic
			  	);
			  $keys = implode(',',array_keys($one));
			  $values = implode("','", array_values($one));
			  //$sql="insert into {$this->mod} ({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
				//$result = $this->conn->query($sql);
					//return $result;
			  
		}
	function getcarbrandList(){
		$sql_cb="select * from carbrand";
		$cb_list = $this->conn->query($sql_cb);
		
		$c_list=array();
		foreach($cb_list as $one){
		    $sql="select * from carbrand where bid=".$one['bid']." order by id  limit 0,4 ";
		   
		    $clist=array();
		    $clist['carbrandname']=$one['carbrandname'];
		    $clist['bid']=$one['bid'];
		    $clist['list']=$this->conn->query($sql);
		    $c_list[]=$clist;
		}
		    return $c_list;
	}
	function getCarphotoList(){
		$sql_cp="select * from carphoto";
		$cp_list = $this->conn->query($sql_cp);
		
		$c_list=array();
		foreach($cp_list as $one){
		    $sql="select * from carphoto where cid=".$one['cid']." order by id  limit 0,4 ";
		   
		    $clist=array();
		    $clist['carname']=$one['carname'];
		    $clist['cid']=$one['cid'];
		    $clist['tid']=$one['tid'];
		    $clist['list']=$this->conn->query($sql);
		    $c_list[]=$clist;
		}
		    return $c_list;
	}

	function getCartypeList(){
		$sql_ct="select * from cartype";
		$ct_list = $this->conn->query($sql_ct);
		
		$c_list=array();
		foreach($ct_list as $one){
		    $sql="select * from cartype where tid=".$one['tid']." order by id  limit 0,4 ";
		   
		    $clist=array();
		    $clist['cartypename']=$one['cartypename'];
		    $clist['tid']=$one['tid'];
		    $clist['list']=$this->conn->query($sql);
		    $c_list[]=$clist;
		}
		    return $c_list;
	}
	/*function getCartype(){
		$sql_ct="select * from cartype";
		$data = $this->conn->query($sql_ct);
		
			return $data;
		}*/

	/*function getCartoonByHint(){
	 $sql_hint="select * from {$this->mod} order by hint desc limit 0,4";
	 $data = $this->conn->query($sql_hint);
			return $data;
	}
	function getCartoonByDowntimes(){
		$sql_downtimes="select * from {$this->mod} order by downtimes desc limit 0,4";
		$data = $this->conn->query($sql_downtimes);
			return $data;

	}*/
	function getCarbrandById($id){
		$sql="select * from carbrand where bid=".$id;
	    $data = $this->conn->query($sql);
		return $data;

    function getCarphotoById($id){
		$sql="select * from carphoto where cid=".$id;
	    $data = $this->conn->query($sql);
		return $data;

    //function getCartypeById($id){
		//$sql="select * from carphoto where tid=".$id;
	    //$data = $this->conn->query($sql);
		//return $data;

	}
	/*function getCartoonTypeByTid($id){
		$sql="select typename from cartoontype where tid={$id}";
	    $data = $this->conn->query($sql);
		return $data;
		var_dump($data);

	}
	function getCartoonTypeByid($id){
		$sql="select tid from {$this->mod} where tid={$id}";
	    $data = $this->conn->query($sql);
	    $sql1= "select typename from cartoontype where tid=".$data['tid'];
	    
	    $data1 = $this->conn->query($sql1);
	   
		return $data1;

	}
	/*function getCartoonByid($id){
		$sql="select * from cartoons where id={$id}";
	    $data = $this->conn->query($sql);
	   
		return $data;
	}*/

	//function search($key){
	//$sql = "select * from {$this->mod} where name like '%{$key}%'";
	///$data = $this->conn->query($sql);
	//return $data;
}
}
?>